#pragma once
#include "Header.h"
#include "resource.h"

class CDlg : public CDialogImpl<CDlg>
{
    CSimpleDialog<IDD_DIALOG_ABOUT> AboutDlg;
    CContainedWindow m_Edit;

public:
    CDlg() : m_Edit(this, 1) { }

public:
    BEGIN_MSG_MAP(CDlg)
        MESSAGE_HANDLER(WM_CLOSE, OnClose)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        COMMAND_HANDLER(IDC_BTN_ABOUT, BN_CLICKED, OnAbout)
        COMMAND_HANDLER(IDC_BTN_INPUT, BN_CLICKED, OnInput)
        COMMAND_HANDLER(IDC_BTN_NOINPUT, BN_CLICKED, OnNoInput)
        COMMAND_HANDLER(IDC_BTN_ABOUT, BN_CLICKED, OnAbout)
        ALT_MSG_MAP(1)
        MESSAGE_HANDLER(WM_CHAR, OnChar)
    END_MSG_MAP()

    enum { IDD = IDD_DIALOG_TEST };

    LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        ::EnableWindow(::GetDlgItem(this->m_hWnd, IDC_BTN_INPUT), FALSE);
        CenterWindow();
        return 0;
    }

    LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        EndDialog(0);
        return 0;
    }

    LRESULT OnAbout(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
        AboutDlg.DoModal();
        return 0;
    }

    LRESULT OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        bHandled = FALSE;
        if (wParam == _T('a'))
            bHandled = TRUE;
        return TRUE;
    }

    LRESULT OnInput(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
        m_Edit.UnsubclassWindow(TRUE);
        ::EnableWindow(::GetDlgItem(this->m_hWnd, IDC_BTN_INPUT), FALSE);
        ::EnableWindow(::GetDlgItem(this->m_hWnd, IDC_BTN_NOINPUT), TRUE);
        return 0;
    }

    LRESULT OnNoInput(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
        m_Edit.SubclassWindow(GetDlgItem(IDC_EDIT_TEST).m_hWnd);
        ::EnableWindow(::GetDlgItem(this->m_hWnd, IDC_BTN_NOINPUT), FALSE);
        ::EnableWindow(::GetDlgItem(this->m_hWnd, IDC_BTN_INPUT), TRUE);
        return 0;
    }
};
